import openai, os
import pandas as pd
from openai.embeddings_utils import get_embedding, cosine_similarity
import openai, os, backoff
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader,StorageContext, load_index_from_storage,QuestionAnswerPrompt

storage_context = StorageContext.from_defaults(persist_dir="./data/index_mr_fujino")
# load index
index = load_index_from_storage(storage_context)
query_engine = index.as_query_engine()
response = query_engine.query("鲁迅先生在日本学习医学的老师是谁？")
print(response)

response = query_engine.query("请问林黛玉和贾宝玉是什么关系？")
print(response)

response = query_engine.query("下面鲁迅先生以第一人称‘我’写的内容，请你用中文总结一下:")
print(response)

print('***********')

response = index.as_query_engine(response_mode='tree_summarize',
    verbose=True).query("下面鲁迅先生以第一人称‘我’写的内容，请你用中文总结一下:")
print(response)
